<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>商品页面</title>
	</script>
	<script type="text/javascript">
		function addCart(productid){

			$.ajax(
				url = "addCart.php",
				type = "POST",
				data = {"productid":productid ,"num":parseInt($("#number").val())},
				succsee = function(response){
				if (response.errno == 0) {
					alert('加入购物车成功');
				}else{
					alert('加入购物车失败');
				}
			}

			);
		}
	</script>

</head>
<body>

	<?php 
		session_start();
		header("Content-type:text/html;charset=utf-8");
		$conn = 	$conn = mysqli_connect('127.0.0.1','root','pwd','admin',3306);//链接数据库('localhost','hotel','vw8jj2','shop',3308);//链接数据库
		mysqli_set_charset($conn,'utf8'); //设定字符集

		$sql_select = "select id,title,num,price from shop_product ";
		$stmt=mysqli_query($conn,$sql_select); 
	 ?>

<table align="center" border="1">
    <?php 
    	while($row=mysqli_fetch_assoc($stmt)){// 循环输出数据
    ?>
     	<tr>
            <td align="center"><img src="../img/pro_img1.jpg"><span class="STYLE2"><?php echo $row['title'] ?></span></td>
            <td align="left"><span class="STYLE2">￥<?php echo $row['price'] ?>元</span></td>
            <td align="center"><span class="STYLE2" id="number"><?php echo $row['num'] ?></span></td>
      
           <td class='m_td'><a href="javascript:addCart(<?php echo $row['id']?>)">加入购物车</a></td>
         

                
        </tr>
        <?php
    }
    ?>
</table>
</body>
</html>


	
	